#!/usr/bin/perl -w

use warnings;
use strict;

use Test::Lono 'no_plan';

BEGIN {
    use_ok( 'Lono::Recipe::Builder' );
};
  
my $name = 'CHICKEN BURRITO';
my @ingredients = ('1/2 cup shredded cheese', 
                   '4 tablespoons guacamole',
                   '4 oz chicken breast', 
                   '4 tablespoons sour cream',
                   '1 tbsp salsa verde',
                   '1 flour tortilla');
my $description = 'A classic Mexican dish.';
my $yield_amount = 1;
my $yield_unit = 'burrito';
my $total_time = '10 minutes';
my $active_time = '5 minutes';
my $preparation = qq[
Preheat the oven to 350.

Cook the chicken breast.  Let cool, and shred with fork and knife.

Heat the tortilla in the oven for 2 minutes.

Place the chicken in the center of the tortilla, top with shredded cheese,
guacamole, sour cream, and salsa verde.

Roll and serve hot.
];
my $nutrition = '12mg fat, 392 calories, 6g sodium';
my $source = 'Epicurious';
my $url = 'http://www.epicurious.com/recipes/recipe_views/views/237666';

my $b_should_work = Lono::Recipe::Builder->new;
isa_ok( $b_should_work, 'Lono::Recipe::Builder' );

$b_should_work->set_name( $name );
foreach my $ing ( @ingredients ) {
    $b_should_work->add_ingredient( $ing );
}
$b_should_work->set_description( $description );
$b_should_work->set_yield_amount( $yield_amount );
$b_should_work->set_yield_unit( $yield_unit );
$b_should_work->set_total_time( $total_time );
$b_should_work->set_active_time( $active_time );
$b_should_work->set_preparation( $preparation );
$b_should_work->set_nutrition( $nutrition );
$b_should_work->set_source( $source );
$b_should_work->set_url( $url );

ok( $b_should_work->has_valid_recipe, 'Setting full recipe.' );
my $r_should_work = $b_should_work->build_recipe;
isa_ok( $r_should_work, 'Lono::Recipe' );

is( $r_should_work->get_name, $name, 'Name matches.' );
is( $r_should_work->get_description, $description, 'Description matches.' );
is( $r_should_work->get_yield_amount, $yield_amount, 
    'Yield amount matches.' );
is( $r_should_work->get_yield_unit, $yield_unit, 'Yield unit matches.' );
is( $r_should_work->get_total_time, $total_time, 'Total time matches.' );
is( $r_should_work->get_active_time, $active_time, 'Active time matches.' );
is( $r_should_work->get_preparation, $preparation, 'Preparation matches.' );
is( $r_should_work->get_nutrition, $nutrition, 'Nutrition matches.' );
is( $r_should_work->get_source, $source, 'Source matches.' );
is( $r_should_work->get_url, $url, 'Url matches.' );

my @got_ingredients = map { $_->get_raw_text } 
                      @{$b_should_work->get_ingredients};

is_deeply_normalized_array( \@got_ingredients, \@ingredients, 
                            'Ingredient lists match.' );
